package com.xxx.lease.web.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xxx.lease.model.entity.*;
import com.xxx.lease.model.enums.ItemType;
import com.xxx.lease.web.app.mapper.*;
import com.xxx.lease.web.app.service.ApartmentInfoService;
import com.xxx.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.xxx.lease.web.app.vo.apartment.ApartmentItemVo;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xxx.lease.web.app.vo.graph.GraphVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {

    @Autowired
    private ApartmentInfoMapper apartmentInfoMapper;
    @Autowired
    private GraphInfoMapper graphInfoMapper;
    @Autowired
    private LabelInfoMapper labelInfoMapper;
    @Autowired
    private RoomInfoMapper roomInfoMapper;
    @Autowired
    private FacilityInfoMapper facilityInfoMapper;


    @Override
    public ApartmentItemVo getApartmentItemVoById(Long apartmentId) {

        ApartmentInfo apartmentInfo = super.getById(apartmentId);

        List<GraphInfo> graphInfoList = graphInfoMapper.selectGraphInfoByIdAndType1(apartmentId, ItemType.APARTMENT);

        List<LabelInfo> labelInfoList = labelInfoMapper.selectLabelInfoByApartmentId(apartmentId);

        BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(apartmentId);

        ApartmentItemVo apartmentItemVo = new ApartmentItemVo();

        BeanUtils.copyProperties(apartmentInfo, apartmentItemVo);

        apartmentItemVo.setGraphVoList(graphInfoList);

        apartmentItemVo.setLabelInfoList(labelInfoList);

        apartmentItemVo.setMinRent(minRent);

        return apartmentItemVo;
    }

    @Override
    public ApartmentDetailVo getDetailById(Long id) {

        ApartmentInfo apartmentInfo = super.getById(id);

        List<GraphVo> graphVoList = graphInfoMapper.selectGraphInfoByIdAndType(id, ItemType.APARTMENT);

        List<LabelInfo> labelInfoList = labelInfoMapper.selectLabelInfoByApartmentId(id);

        List<FacilityInfo> facilityInfoList = facilityInfoMapper.selectFacilityInfoByApartmentId(id);

        BigDecimal minRent = roomInfoMapper.selectMinRentByApartmentId(id);

        boolean isDelete = apartmentInfo.getIsDeleted() == 1;

        ApartmentDetailVo apartmentDetailVo = new ApartmentDetailVo();

        BeanUtils.copyProperties(apartmentInfo, apartmentDetailVo);

        apartmentDetailVo.setGraphVoList(graphVoList);

        apartmentDetailVo.setLabelInfoList(labelInfoList);

        apartmentDetailVo.setFacilityInfoList(facilityInfoList);

        apartmentDetailVo.setMinRent(minRent);

        apartmentDetailVo.setIsDelete(isDelete);

        return apartmentDetailVo;
    }
}




